﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.SetTemplateAndKeywords.CApSetTemplateAndKeywordsValidator
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.Generic;
using System.Collections.ObjectModel;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Olp;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.SetTemplateAndKeywords;

internal class CApSetTemplateAndKeywordsValidator : ITxValidator
{
  private TxRobot m_robot;
  private List<ITxRoboticOperation> m_operations;

  internal CApSetTemplateAndKeywordsValidator(TxRobot robot, List<ITxRoboticOperation> operations)
  {
    this.m_robot = robot;
    this.m_operations = operations;
  }

  public ITxObject GetObject(string str)
  {
    ITxObject itxObject1 = (ITxObject) null;
    TxObjectList txObjectList = (TxObjectList) null;
    if (!string.IsNullOrEmpty(str))
      txObjectList = TxApplication.ActiveDocument.GetObjectsByName(str);
    if (txObjectList != null && ((Collection<ITxObject>) txObjectList).Count > 0)
    {
      string errorMessage = (string) null;
      foreach (ITxObject itxObject2 in (Collection<ITxObject>) txObjectList)
      {
        if (this.IsValidObject(itxObject2, out errorMessage))
        {
          itxObject1 = itxObject2;
          break;
        }
      }
    }
    return itxObject1;
  }

  public string GetText(ITxObject obj)
  {
    string text = string.Empty;
    if (obj != null)
      text = obj.Name;
    return text;
  }

  public bool IsValidObject(ITxObject obj, out string errorMessage)
  {
    bool flag = false;
    errorMessage = (string) null;
    TxOlpControllerUtilities controllerUtilities = new TxOlpControllerUtilities();
    switch (obj)
    {
      case null:
        errorMessage = CApSetTemplateAndKeywordsStringTable.InvalidObject;
        goto label_12;
      case TxGenericRoboticOperation _:
      case ITxContinuousOperation _:
      case TxWeldOperation _:
        if (TxRobot.op_Equality(controllerUtilities.GetRobot(obj as ITxOperation), (ITxObject) this.m_robot))
        {
          flag = true;
          break;
        }
        errorMessage = CApSetTemplateAndKeywordsStringTable.InvalidOperation;
        break;
      default:
        errorMessage = CApSetTemplateAndKeywordsStringTable.InvalidObject;
        break;
    }
    if (flag)
    {
      if (this.m_operations.Contains(obj as ITxRoboticOperation))
      {
        flag = false;
        errorMessage = CApSetTemplateAndKeywordsStringTable.SourceOperation;
      }
      else
      {
        TxRoboticParam parameter = (obj as ITxRoboticOperation).GetParameter("OLP_XML_DOWNLOAD_TEMPLATE");
        if (parameter != null && parameter is TxRoboticStringParam)
        {
          flag = true;
        }
        else
        {
          flag = false;
          errorMessage = CApSetTemplateAndKeywordsStringTable.MissingTemplateName;
        }
      }
    }
label_12:
    return flag;
  }

  public bool IsValidText(string text, out string errorMessage)
  {
    return this.IsValidObject(this.GetObject(text), out errorMessage);
  }
}
